<?php


// 可以用 pack 二进制

/*
 * 通过用 substr 来确保字段值不会缺失，另 str_pad 确保数据不会过短
 * */

$books = [
    ['elmer gantry', 'sinclair lewis', 1927],
    ['the scarlatti Inheritance', 'Robert Ludlum ', 1971],
    ['the parsifal mosaic', 'william styron', 1979],
];

foreach ($books as $book) {
    $title = str_pad(substr($book[0], 0, 26), 26, '.');
    $author = str_pad(substr($book[1], 0, 15), 15, '.');
    $year = str_pad(substr($book[2], 0, 4), 4, '.');
    print "$title$author$year\n";
}

// 结果
/*
elmer gantry..............sinclair lewis.1927
the scarlatti Inheritance.Robert Ludlum .1971
the parsifal mosaic.......william styron.1979
*/


